<?php
	require_once('configure.php');
	$date = $_GET['tanggal'];
	$karyawan_id = $_GET['karyawan_id'];
	$status = $_GET['status'];
	$jam_in = $_GET['jam_in'];
	$jam_out = $_GET['jam_out']; 
	
	$query1 = "SELECT * FROM temp_proses_finger WHERE ";
	if( $status == 'IN' ){ 
		$query = " jam_in ='{$jam_in}' AND correct_in='Y' AND margin_in ='0' AND margin_calc = '0' ";
	}else
	if($status == 'OUT' ){
		$query = " jam_out ='{$jam_out}' AND correct_out='Y' AND margin_out ='0' AND margin_calc = '0' ";
	
	} 
	$query2 .= " AND karyawan_id = {$karyawan_id} AND proses_date = '{$date}' ";
	$result = my_query($query1 . $query. $query2);
	if(my_num_rows($result) > 0){
		$query2 = "UPDATE temp_proses_finger SET ";  
		if( $status == 'IN' ){ 
			$query = " jam_in ='00:00:01' , correct_in='N' , margin_in ='0' , margin_calc = '0' ";
			$jam = $jam_in;
		}else
		if($status == 'OUT' ){
			$query = " jam_out ='00:00:01' , correct_out='N' , margin_out ='0' , margin_calc = '0' "; 
			$jam = $jam_out;
		}
		$query .= " WHERE karyawan_id = {$karyawan_id} AND proses_date = '{$date}' ";
		$s = my_query($query2 . $query); 
		
		$queryX = "DELETE FROM a_mesin_capture WHERE karyawan_mesin_id ={$karyawan_id} "; 
		$queryX .= " AND  manual ='Y' "; 
		$queryX .= " AND  DATE(datetime_mesin_log) ='{$date} {$jam}' "; 
		$s2 = my_query($queryX);
	
	}else{
		$query2 = "UPDATE temp_proses_finger SET ";  
		if( $status == 'IN' ){ 
		$query = " jam_in ='{$jam_in}' , correct_in='Y' , margin_in ='0' , margin_calc = '0' ";
		}else
		if($status == 'OUT' ){
			$query = " jam_out ='{$jam_out}' , correct_out='Y' , margin_out ='0' , margin_calc = '0' ";
		
		} 
		$query .= " WHERE karyawan_id = {$karyawan_id} AND proses_date = '{$date}' ";
		
		$s = my_query($query2 . $query); 
		
		$jam =  ( $status == 'IN') ? $jam_in : $jam_out ; 
		$datas = array(
			'karyawan_mesin_id'	=> my_type_data_str($karyawan_id),
			'manual'=> my_type_data_str('Y'),
			'mesin_lokasi_id'=> my_type_data_str(0),
			'datetime_mesin_log'=> my_type_data_str($date.' '.$jam),
			'datetime_added'=> my_type_data_function('NOW()' )
		);
		my_insert_record( 'a_mesin_capture' , $datas);
		
	}
var_dump($_GET);
?>